<?php

namespace App\Http\Controllers\Notify;

use App\Http\Controllers\BaseController;
use App\Http\Requests\BjNotifyRequest;
use App\Logic\BaoJianMachineLogic;
use App\Logic\LogLogic;

class BjNotifyController extends BaseController
{
    public function bjResponse($message = 'OK', $code = 20000)
    {
        $res = [
            'code'    => $code,
            'message' => $message,
            'data'    => []
        ];

        return response()->json($res);
    }

    /**
     * @notes 门状态回调
     * @param BjNotifyRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @author Evil丿
     * @date 2024/12/12 14:12
     */
    public function BjDoorStatus(BjNotifyRequest $request)
    {
        $post = $request -> post();

        LogLogic::setBjLogs($post['eventId'],'door_notify', $post);

        $res = BaoJianMachineLogic::updateOpenEvent($post);

        if($res === false) {
            return $this->bjResponse(BaoJianMachineLogic::getErrorMessage(), 404);
        }

        return $this->bjResponse();
    }

    /**
     * @notes 视频通知
     * @param BjNotifyRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @author Evil丿
     * @date 2024/12/12 14:12
     */
    public function BjVideoStatus(BjNotifyRequest $request)
    {
        $post = $request -> post();

        LogLogic::setBjLogs($post['eventId'],'video_notify', $post);

        $res = BaoJianMachineLogic::updateOpenEventVideo($post);

        if($res === false) {
            return $this->bjResponse(BaoJianMachineLogic::getErrorMessage(), 404);
        }

        return $this->bjResponse();
    }

    /**
     * @notes 设备状态通知
     * @param BjNotifyRequest $request
     * @return \Illuminate\Http\JsonResponse
     * @author Evil丿
     * @date 2024/12/12 14:12
     */
    public function BjMachineStatus(BjNotifyRequest $request)
    {
        $post = $request -> post();

        $res = BaoJianMachineLogic::updateMachineStatus($post);

        if($res === false) {
            return $this->bjResponse(BaoJianMachineLogic::getErrorMessage(), 404);
        }

        return $this->bjResponse();
    }
}
